home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / demos / retinarave / include / decrunch.s < prev    next >
Text File  |  1980-01-03  |  2KB  |  105 lines

  1. ;====================================================
  2. ;
  3. ;        POWERPACKER DECRUNCH ROUTINE
  4. ;
  5. ; a3 -> destination, a0 -> longword after crunched,
  6. ; a5 -> ptr to eff., a6 -> decr.col
  7. ;
  8. ; destroys a0-a6 and d0-d7
  9. ;====================================================
  10.  
  11. Unpack:
  12.  
  13.     moveq #3,d6
  14.     moveq #7,d7
  15.     moveq #1,d5
  16.     move.l a3,a2            ; remember start of file
  17.     move.l -(a0),d1            ; get file length and empty bits
  18.     tst.b d1
  19.     beq.s NoEmptyBits
  20.     bsr.s ReadBit        ; this will always get the next long (D5 = 1)
  21.     subq.b #1,d1
  22.     lsr.l d1,d5            ; get rid of empty bits
  23. NoEmptyBits:
  24.     lsr.l #8,d1
  25.     add.l d1,a3            ; a3 = endfile
  26. ;    move.l d1,length
  27.  
  28. LoopCheckCrunch:
  29.     bsr.s ReadBit            ; check if crunch or normal
  30.     bcs.s CrunchedBytes
  31. NormalBytes:
  32.     moveq #0,d2
  33. Read2BitsRow:
  34.     moveq #1,d0
  35.     bsr.s ReadD1
  36.     add.w d1,d2
  37.     cmp.w d6,d1
  38.     beq.s Read2BitsRow
  39. ReadNormalByte:
  40.     moveq #7,d0
  41.     bsr.s ReadD1
  42.     move.b d1,-(a3)
  43.     dbf d2,ReadNormalByte
  44.     cmp.l a3,a2
  45.     bcs.s CrunchedBytes
  46.     rts
  47. ReadBit:
  48.     lsr.l #1,d5        ; this will also set X if d5 becomes zero
  49.     beq.s GetNextLong
  50.     rts
  51. GetNextLong:
  52.     move.l -(a0),d5
  53.     roxr.l #1,d5            ; X-bit set by lsr above
  54.     rts
  55. ReadD1sub:
  56.     subq.w #1,d0
  57. ReadD1:
  58.     moveq #0,d1
  59. ReadBits:
  60.     lsr.l #1,d5        ; this will also set X if d5 becomes zero
  61.     beq.s GetNext
  62. RotX:
  63.     roxl.l #1,d1
  64.     dbf d0,ReadBits
  65.     rts
  66. GetNext:
  67.     move.l -(a0),d5
  68.     roxr.l #1,d5            ; X-bit set by lsr above
  69.     bra.s RotX
  70. CrunchedBytes:
  71.     moveq #1,d0
  72.     bsr.s ReadD1            ; read code
  73.     moveq #0,d0
  74.     move.b 0(a5,d1.w),d0        ; get number of bits of offset
  75.     move.w d1,d2            ; d2 = code = length-2
  76.     cmp.w d6,d2        ; if d2 = 3 check offset bit and read length
  77.     bne.s ReadOffset
  78.     bsr.s ReadBit            ; read offset bit (long/short)
  79.     bcs.s LongBlockOffset
  80.     moveq #7,d0
  81. LongBlockOffset:
  82.     bsr.s ReadD1sub
  83.     move.w d1,d3            ; d3 = offset
  84. Read3BitsRow:
  85.     moveq #2,d0
  86.     bsr.s ReadD1
  87.     add.w d1,d2            ; d2 = length-1
  88.     cmp.w d7,d1            ; cmp with #7
  89.     beq.s Read3BitsRow
  90.     bra.s DecrunchBlock
  91. ReadOffset:
  92.     bsr.s ReadD1sub            ; read offset
  93.     move.w d1,d3            ; d3 = offset
  94. DecrunchBlock:
  95.     addq.w #1,d2
  96. DecrunchBlockLoop:
  97.     move.b 0(a3,d3.w),-(a3)
  98.     dbf d2,DecrunchBlockLoop
  99. EndOfLoop:
  100.     move.w a3,(a6)            ; flash register bits
  101.     cmp.l a3,a2
  102.     bcs LoopCheckCrunch
  103.  
  104.     rts
  105.